home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / NewXTeXT / XText0.9beta2 / XText.subproj / XTAction.h < prev    next >
Encoding:
Text File  |  1995-07-28  |  3.6 KB  |  144 lines

  1. #import <objc/Object.h>
  2. #import <dpsclient/event.h>
  3.  
  4. /*    An XTAction specifies the action to be taken in response to a key event.
  5.     When a key event occurs, the applyTo:event: method is invoked; this is
  6.     the key method that must be implemented by the subclasses of XTAction.
  7.  
  8.     Actions normally return self from the applyTo:event: method, but by
  9.     returning nil they can cause the event to be handled normally by XText0's
  10.     superclass (i.e. Text).
  11.  
  12.     The class method undefinedAction returns a default action that invokes
  13.     the text object's unboundKey method.
  14. */
  15.  
  16. @interface XTAction:Object
  17. {
  18. }
  19. + undefinedAction;
  20. - applyTo:xtext event:(NXEvent *)event;
  21. @end
  22.  
  23. #define MAPPED_KEYS      256            //    table size for a dispatch action
  24. #define NUM_MASKS        7              // keyboard independent flags
  25. /* 
  26. NX_ALPHASHIFTMASK Shift lock
  27. NX_SHIFTMASK      Shift key
  28. NX_CONTROLMASK      Control key 
  29. NX_ALTERNATEMASK  Alt key
  30. NX_COMMANDMASK      Command key 
  31. NX_NUMERICPADMASK Number pad key
  32. NX_HELPMASK          Help key
  33.  
  34.  charCodes are 128 * event->data.key.charCode,
  35.         + 1 if shift lock,
  36.         + 2 if shift,
  37.         + 4 if control,
  38.         + 8 if alt
  39.         + 16 if command
  40.         + 32 if numeric keypad
  41.         + 64 if help key
  42. */
  43.  
  44. #define CHAR_CODES  (MAPPED_KEYS * (1 << NUM_MASKS) )//combinations/key
  45.  
  46. typedef int charCode;
  47. typedef XTAction *actionTbl[CHAR_CODES];
  48.  
  49. /*    XTMsg0Action, XTMsg1Action, and XTMsg2Action are subclasses of XTAction
  50.     that send a specified message to the text object with 0, 1, or 2 args.
  51. */
  52.  
  53. @interface XTMsg0Action:XTAction
  54. {
  55.     SEL    action_sel;
  56. }
  57. - initSel:(SEL)sel;
  58. @end
  59.  
  60. @interface XTMsg1Action:XTAction
  61. {
  62.     SEL    action_sel;
  63.     int action_arg;
  64. }
  65. - initSel:(SEL)sel arg:(int)arg;
  66. @end
  67.  
  68. @interface XTMsg2Action:XTAction
  69. {
  70.     SEL    action_sel;
  71.     int action_arg1;
  72.     int action_arg2;
  73. }
  74. - initSel:(SEL)sel arg:(int)arg1 arg:(int)arg2;
  75. @end
  76.  
  77. /*    XTDispatchAction is a subclass of XTAction that maintains a dispatch
  78.     table of other actions and selects one based on the key pressed.  The
  79.     methods are
  80.         init                initializes all actions to `nil'.  XText
  81.                             has default NeXT Text Class behavior 
  82.  
  83.         initBase:estream:    the first argument is a string naming a 'base'
  84.                             set of initial bindings; the only values currently
  85.                             supported are "none". 
  86.  
  87.         loadFromFile:fullName estream:errs
  88.                             loads keybindings from a file.  Comments are
  89.                             lines in the file beginning with `#'.  This 
  90.                             method enables developers to load keybinding
  91.                             files from their .app wrapper directories.
  92.  
  93.         bindKey:toAction:estream:
  94.                             bind a key to a specified action; an action of nil
  95.                             will cause the key to be handled normally by the
  96.                             Text class
  97.  
  98.         addBindings:estream:
  99.                             parse and install the bindings specified by a
  100.                             string
  101.  
  102.     The estream argument is used to report any errors; if it is nil, the
  103.     default error stream (which simply pops up an alert panel) is used.
  104. */
  105.  
  106. @interface XTDispatchAction:XTAction
  107. {
  108.     actionTbl actions;
  109. }
  110. - init;
  111. - initBase:(const char *)base estream:errs;
  112. - loadFromFile:(char *)fullName estream:errs;
  113. - bindKey:(charCode)key toAction:action estream:errs;
  114. @end
  115.  
  116. @interface XTDispatchAction(parsing)
  117. - addBindings:(const char *)bindings estream:errs;
  118. @end
  119.  
  120. /*    XTEventMsgAction is a subclass of XTAction that sends a specified
  121.     message to the text object, passing the event as an argument.
  122.     This is useful for implementing some special-purpose prefix commands
  123.     like 'quote next character'
  124. */
  125.  
  126. @interface XTEventMsgAction:XTAction
  127. {
  128.     SEL action_sel;
  129. }
  130. - initSel:(SEL)sel;
  131. @end
  132.  
  133. /*    XTSeqAction is a subclass of XTAction that invokes a sequence of
  134.     subactions.
  135. */
  136.  
  137. @interface XTSeqAction:XTAction
  138. {
  139.     int length;
  140.     XTAction **actions;
  141. }
  142. - initLength:(int)len actions:(XTAction **)acts;
  143. @end
  144.